#include "StdAfx.h"
#include "videoWindow.h"


namespace DSP
{
	videoWindow::videoWindow(ATL::CComPtr<IBasicVideo>& pVideo, ATL::CComPtr<IVideoWindow>& pWindow)
	{
		this->pVideo = pVideo;
		this->pWindow = pWindow;
		calcAspectRatio();
	}


	videoWindow::~videoWindow(void)
	{
		pWindow->put_Visible(OAFALSE);
		pWindow->put_Owner(NULL);
	}


	void videoWindow::setVideoWindow(HWND hwnd)
	{
		HRESULT hr = pWindow->put_Owner(OAHWND(hwnd));
		if(FAILED(hr))
			throw errorInfo("Error: Can not put owner.", hr);
		hr = pWindow->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
		if(FAILED(hr))
			throw errorInfo("Error: Can not put window style.", hr);
	}


	void videoWindow::getWindowPosition(long* left, long* top, long* width, long* height)
	{
		HRESULT hr = pWindow->GetWindowPosition(left, top, width, height);
		if(FAILED(hr))
			throw errorInfo("Error: Can not get window position.", hr);
	}


	void videoWindow::setWindowPosition(long left, long top, long width, long height)
	{
		HRESULT hr = pWindow->SetWindowPosition(left, top, width, height);
		if(FAILED(hr))
			throw errorInfo("Error: Can not set window position.", hr);
	}


	void videoWindow::getVideoSize(long* pWidth, long* pHeight)
	{
		HRESULT hr = pVideo->GetVideoSize(pWidth, pHeight);
		if(FAILED(hr))
			throw errorInfo("Error: Can not get video size", hr);
	}


	void videoWindow::calcAspectRatio()
	{
		long width, height;
		getVideoSize(&width, &height);
		aspectRatio = static_cast<double>(width)/static_cast<double>(height);
	}


	double videoWindow::getAspectRatio() const
	{
		return aspectRatio;
	}
}